<template>
	<view class="agent-account" :style="{background:pageColor}" v-if="isLoad">
		<view class="fill-base pd-lg">
			<view class="pt-md pb-md c-title text-bold" style="font-size:34rpx">账号信息</view>
			<block v-if="options.agent">
				<view class="flex-warp pb-lg">
					<view class="f-paragraph">账号名称</view>
					<view class="f-desc">{{detail.username}}</view>
				</view>
				<view class="flex-warp pb-lg">
					<view class="f-paragraph">账号密码</view>
					<view class="f-desc">{{detail.passwd_text}}</view>
				</view>
				<view class="flex-warp pb-lg">
					<view class="f-paragraph">真实姓名</view>
					<view class="f-desc">{{detail.agent_name}}</view>
				</view>
				<view class="flex-warp pt-lg pb-lg b-1px-t">
					<view class="f-paragraph">当前等级</view>
					<view class="f-desc">{{cityType[detail.city_type]}}代理({{detail.city_name}})</view>
				</view>
				<!-- 省/市 查下级；区县查上级 -->
				<view class="flex-warp pb-lg" v-if="detail.city_type != 3">
					<view class="f-paragraph">关联上级{{$t('action.agentName')}}</view>
					<view class="f-desc">
						{{detail.top_data && detail.top_data.hasOwnProperty('username')?detail.top_data.username:'-'}}
					</view>
				</view>
				<view class="flex-warp pb-lg" v-if="detail.city_type != 2">
					<view class="f-paragraph">关联下级{{$t('action.agentName')}}</view>
					<view class="f-desc">
						<block v-if="detail.sub_data.length==0">-</block>
						<view class="mb-sm" v-for="(item,index) in detail.sub_data" :key="index">{{item.agent_name}}
						</view>
					</view>
				</view>
			</block>
			<block v-else>
				<view class="flex-warp pb-lg">
					<view class="f-paragraph">手机号</view>
					<view class="f-desc">{{detail.mobile || '-'}}</view>
				</view>
				<block v-if="configInfo.plugAuth.old_agentport">
					<view class="flex-warp pb-lg">
						<view class="f-paragraph">密码</view>
						<view class="f-desc">{{detail.passwd || '-'}}</view>
					</view>
					<view @tap.stop="$util.goUrl({url:`/agent/pages/account/reset`})"
						class="setting-btn flex-center f-title c-base radius-10" :style="{background:primaryColor}">
						去设置</view>
				</block>
			</block>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				isLoad: false,
				options: {},
				detail: {},
				cityType: {
					1: '城市',
					2: '区县',
					3: '省'
				},
			}
		},
		computed: mapState({
			configInfo: state => state.config.configInfo,
		}),
		onLoad(options) {
			let {
				agent = 0
			} = options
			options.agent = agent * 1
			this.options = options
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			...mapMutations(['getConfigInfo']),
			async initIndex(refresh = false) {
				this.$util.showLoading()
				let {
					agent
				} = this.options
				let methodKey = agent ? 'agent' : 'admin'
				if (!agent) {
					await this.getConfigInfo()
				}
				this.detail = await this.$api[methodKey].adminInfoData()
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})
				this.isLoad = true
				this.$util.hideAll()
				// #ifdef H5
				if (!refresh) {
					this.$jweixin.hideOptionMenu()
				}
				// #endif
			},
			initRefresh() {
				this.initIndex(true)
			},
			toJump(key, index) {
				let {
					url
				} = this[key][index]
				this.$util.goUrl({
					url
				})
			},
		},
		filters: {
			handlePassWord(val) {
				let len = val.length
				let text = val.substring(0, len > 6 ? 3 : 1) + '***'
				text += val.substring(len == 6 ? len - 2 : len - 3, len)
				return text
			}
		}
	}
</script>


<style lang="scss">
	.agent-account {

		.f-paragraph {
			width: 210rpx;
			color: #4A4A4A;
			padding-right: 10rpx;
		}

		.f-desc {
			width: 480rpx;
			color: #777777;
		}

		.setting-btn {
			width: 630rpx;
			height: 110rpx;
			margin: 30rpx auto;
		}
	}
</style>